package cn.sundat.web;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.mysql.fabric.xmlrpc.base.Data;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import cn.sundat.model.Company;
import cn.sundat.model.CompanyProduct;
import cn.sundat.model.PageBean;
import cn.sundat.model.Product;
import cn.sundat.service.CompanyService;
import cn.sundat.utils.FastJsonUtils;

/**
 * 公司action
 * author LeeLiang
 */
public class CompanyAction extends ActionSupport implements ModelDriven<Company>{
	
	private Integer currPage = 1;
	private Integer pageSize = 8;

	public void setCurrPage(Integer currPage) {
		if(currPage==null) {
			currPage=1;
		}else {
			this.currPage = currPage;
		}
	}
	
	public void setPageSize(Integer pageSize) {
		if(currPage==null) {
			pageSize=2;
		}else {
			this.pageSize = pageSize;
		}
	}
	
	private Company company = new Company();
	@Override
	public Company getModel() {
		return company;
	}
	
	//注解方式注入companyService
	@Resource(name="companyService")
	private CompanyService companyService;
	
	
	public String save() {
		System.out.println("进来了");
		//添加时间
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String date = format.format(new Date());
		company.setComp_time(date);
		companyService.save(company);
		return NONE;
	}
	
	/**
	 * 分页查询所有的公司类
	 * @return
	 */
	public String findByPageBean() {
		System.out.println("当前页码是:"+currPage);
		PageBean<Company> pb =  companyService.findByPage(currPage, pageSize);
		ServletActionContext.getRequest().setAttribute("pblist", pb);
		return "clist";
	}
	
	
	
}
